package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.SjAiChatQuestionAndAnswerVO;
import com.ruoyi.system.domain.vo.SjAiChatTitleVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ISjAiChatService;
import com.ruoyi.system.domain.SjAiChat;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 智能问答Controller
 * 
 * @author zrr
 * @date 2024-11-04
 */
@RestController
@RequestMapping("/aiChat/aiChat")
public class SjAiChatController extends BaseController
{
    @Autowired
    private ISjAiChatService sjAiChatService;

    /**
     * 查询智能问答列表
     */
    @PreAuthorize("@ss.hasPermi('aiChat:aiChat:list')")
    @GetMapping("/list")
    public TableDataInfo list(com.ruoyi.system.domain.SjAiChat sjAiChat)
    {
        startPage();
        List<com.ruoyi.system.domain.SjAiChat> list = sjAiChatService.selectSjAiChatList(sjAiChat);
        return getDataTable(list);
    }

    /**
     * 导出智能问答列表
     */
    @PreAuthorize("@ss.hasPermi('aiChat:aiChat:export')")
    @Log(title = "智能问答", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, com.ruoyi.system.domain.SjAiChat sjAiChat)
    {
        List<com.ruoyi.system.domain.SjAiChat> list = sjAiChatService.selectSjAiChatList(sjAiChat);
        ExcelUtil<com.ruoyi.system.domain.SjAiChat> util = new ExcelUtil<com.ruoyi.system.domain.SjAiChat>(com.ruoyi.system.domain.SjAiChat.class);
        util.exportExcel(response, list, "智能问答数据");
    }

    /**
     * 获取智能问答详细信息
     */
    @PreAuthorize("@ss.hasPermi('aiChat:aiChat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(sjAiChatService.selectSjAiChatById(id));
    }

    /**
     * 新增智能问答
     */
    @PreAuthorize("@ss.hasPermi('aiChat:aiChat:add')")
    @Log(title = "智能问答", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody com.ruoyi.system.domain.SjAiChat sjAiChat)
    {
        return toAjax(sjAiChatService.insertSjAiChat(sjAiChat));
    }

    /**
     * 修改智能问答
     */
    @PreAuthorize("@ss.hasPermi('aiChat:aiChat:edit')")
    @Log(title = "智能问答", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody com.ruoyi.system.domain.SjAiChat sjAiChat)
    {
        return toAjax(sjAiChatService.updateSjAiChat(sjAiChat));
    }

    /**
     * 删除智能问答
     */
    @PreAuthorize("@ss.hasPermi('aiChat:aiChat:remove')")
    @Log(title = "智能问答", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(sjAiChatService.deleteSjAiChatByIds(ids));
    }

    /**
     * 历史记录标题查询
     */
    @PreAuthorize("@ss.hasPermi('aiChat:aiChat:history')")
    @GetMapping(value = "/history/{userId}")
    public List<SjAiChatTitleVO> historyTitle(@PathVariable("userId") String userId)
    {
        List<SjAiChatTitleVO> sjAiChatTitleVOList = sjAiChatService.selectSjAiChatTitleById(userId);
        return sjAiChatTitleVOList;
    }

    /**
     * 查询对应标题问答记录
     */
    @PostMapping(value = "/questionAndAnswer")
    public List<SjAiChatQuestionAndAnswerVO> questionAndAnswer(@RequestBody com.ruoyi.system.domain.SjAiChat sjAiChat)
    {
        return sjAiChatService.selectSjAiChatQuestionAndAnswer(sjAiChat);
    }

    /**
     * 查询最大标题ID
     */
    @PreAuthorize("@ss.hasPermi('aiChat:aiChat:lastTitleId')")
    @GetMapping(value = "/lastTitleId/{userId}")
    public Long selectLastTitleId(@PathVariable("userId") String userId)
    {
        return sjAiChatService.selectLastTitleId(userId);
    }
}
